using UnityEngine;
using QFramework;
using System.Runtime.CompilerServices;

// 1.请在菜单 编辑器扩展/Namespace Settings 里设置命名空间
// 2.命名空间更改后，生成代码之后，需要把逻辑代码文件（非 Designer）的命名空间手动更改
namespace QFramework.Example
{
	public partial class MpFiveBullet : BulletFathers
	{
        public float moveSpeed;
        public Vector2 dics;
        public float maxFlyTime;

        public Transform startPos;
        public override Transform StartPos => startPos;

        public override BoxCollider2D boxCollider => SelfBoxCollider2D;
        private int hotIndex = 0;
        public override int HotIndex => hotIndex;

        public override float MaxBulletFlyTime => maxFlyTime;

        void Start()
		{
            //SetBulletScale(DataManager.Instance.mpFiveModel.);

            SelfBoxCollider2D.OnTriggerEnter2DEvent(collider =>
            {
                var hurtbox = collider.GetComponent<HitHurtBox>();
                if (hurtbox != null)
                {
                    if (hurtbox.Owner.CompareTag("Enemy"))
                    {
                        Debug.Log("子弹攻击到了enemy");
                        var enemys = hurtbox.Owner.GetComponent<EnemyFathers>();



                        if (enemys is IEnemy enemy)
                        {
                            Debug.Log("进入伤害计算");
                            DamageSystem.SetDamage(DataManager.Instance.mpFiveModel.MpFiveDamage.Value, enemy);
                            this.DestroyGameObjGracefully();
                        }



                    }
                }
            }).UnRegisterWhenGameObjectDestroyed(gameObject);

        }


        private void Update()
        {
            //Dis();
            transform.Translate(dics * Time.deltaTime * moveSpeed);
        }

        public override void Dis()
        {
            base.Dis();
            if ((this.transform.position - Player.Instance.transform.position).magnitude > 6)
            {
                Destroy(this.gameObject);
            }
        }

        public override void SetBulletScale(float scale)
        {
            base.SetBulletScale(scale);
        }

        public override void SetBulletSpeed(float speed)
        {
            base.SetBulletSpeed(speed);
            moveSpeed = speed;
        }

        public override void BulletMoveDic(Vector2 dic)
        {
            base.BulletMoveDic(dic);
            dics = dic;
        }
    }
}
